package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/8/28
 */
@RestController
@RequestMapping("cities")
@RefreshScope
public class CityController {
    @Autowired
    private CityService cityService;
    @GetMapping
    public List<City> findAll(){
        List<City> cities =   cityService.findAll();
        return  cities ;
    }

    @PostMapping
    public City addCity(@RequestBody City city){
        City cty = cityService.addCity(city);
        return  cty ;
    }


    @GetMapping("{cityId}")
    public City getById( @PathVariable Integer cityId){
       City city =   cityService.getById(cityId);
        return  city ;
    }


}
